package com.antis.olsl.main.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.antis.olsl.main.R;
import com.antis.olsl.main.bean.HomePageMenuInfo;

import java.util.ArrayList;

/**
 * @ProjectName: ATS_OLSL
 * @Package: com.antis.olsl.adapter
 * @ClassName: HomePageMenuGridAdapter
 * @Description: java类作用描述
 * @Author: 羊琪
 * @CreateDate: 2020/4/1 20:10
 * @UpdateDate: 2020/4/1 20:10
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class FunctionMenuGridAdapter extends BaseAdapter {
    Context context;
    ArrayList<HomePageMenuInfo> menuInfos = new ArrayList<>();

    public FunctionMenuGridAdapter(Context context, ArrayList<HomePageMenuInfo> menuInfos) {
        this.context = context;
        this.menuInfos = menuInfos;
    }

    public FunctionMenuGridAdapter(Context context) {
        this.context = context;
    }

    public void setMenuInfos(ArrayList<HomePageMenuInfo> menuInfos) {
        if(menuInfos == null){
            this.menuInfos.clear();
        }else {
            this.menuInfos = menuInfos;
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return menuInfos.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.griditem_homepage_menu, null);
            holder.tvMenuName = view.findViewById(R.id.tv_menuName);
            holder.imageView = view.findViewById(R.id.imageView);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tvMenuName.setText(menuInfos.get(i).getMenuName());
        holder.imageView.setImageResource(menuInfos.get(i).getImageId());
        return view;
    }

    private static class ViewHolder {
        TextView tvMenuName;
        ImageView imageView;
    }
}
